<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Laporan_harian_model extends CI_Model {
	
	public function __construct()
	{
		parent::__construct();
	}
	
	function get($id = null) 
	{
		//$this->db->select()->from('laporan_harian');
		if ($id != null) 
		{
			//$this->db->where('id_laporan_harian', $id);
			$query = $this->db->query("SELECT lh.*, p.uraian FROM laporan_harian lh, project_pekerjaan p WHERE lh.id_laporan_harian='$id' AND p.kode=lh.kode_pekerjaan");
		}
		else 
		{
			//$this->db->order_by('id_laporan_harian');
			$query = $this->db->query("SELECT lh.*, p.uraian FROM laporan_harian lh, project_pekerjaan p WHERE p.kode=lh.kode_pekerjaan");
		}
 
		//$query = $this->db->get();
 
		if ($id != null) 
		{
			return $query->row_array();
		}
		else 
		{
			return $query->result_array();
		}
	}
	
	function getDetail($id)
	{
		$query = $this->db->query("SELECT lhd.pay_item, lhd.volume, lhd.awal, lhd.akhir, lhd.tanggal_mulai, lhd.jam_mulai, lhd.tanggal_selesai, lhd.jam_selesai, b.uraian, b.satuan FROM laporan_harian_detail lhd, project_boq b WHERE lhd.id_laporan_harian='$id' AND lhd.pay_item=b.pay_item");
		return $query->result_array();
	}
	
	public function saveLaporan($data)
	{
		if($this->db->insert('laporan_harian', $data))
		{
			return $this->db->insert_id();
		}
		else
		{
			return false;
		}
	}
	
	public function saveLaporanDetail($data)
	{
		if($this->db->insert('laporan_harian_detail', $data))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public function is_laporanHarian_exist($id)
	{
		$query = $this->db->get_where('laporan_harian', array('id' => $id));
		if($query->num_rows() > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public function update($id,$data)
	{
		$this->db->where('id', $pay_item);
		$this->db->update('laporan_harian', $data); 
	}
	
	public function insert($data)
	{
		if($this->db->insert('laporan_harian', $data))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public function delete($id)
	{
		$this->db->delete('laporan_harian', array('id' => $id) ); 
	}
}